﻿Imports TheStoreDepot
Imports System.Data.SqlClient


Public Class Form1
    Dim TestConnectionString As String = "Data Source=LONYPLASQL01;Initial Catalog=TheStore; User Id=TheStoreUser; Password=Pukka462854CDog;"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        PBox.zConnectionString = TestConnectionString
        PBox.zProviderTypeCodeFilter = "Acade"

        LaBoxCtrl1.zConnectionString = TestConnectionString
        LaBoxCtrl1.zAllOptionAvailable = True

        PeriodBoxCtrl1.zConnectionString = TestConnectionString

        PeriodBoxCtrl1.zSelectedPeriod_ID = 2011121

        TerritoryBoxCtrl1.zConnectionString = TestConnectionString
        TerritoryBoxCtrl1.zAllOptionAvailable = True

        Dim DS As New DataView
        Dim s As Boolean

        DS = LoadDataView("Select * from all_provider_fields", TestConnectionString, s)
        FilterCtrl1.zDataView = DS

        FilterCtrl1.AddFilterOption()



        DG.DataSource = DS


    End Sub

    Function LoadDataView(ByVal SqlString As String, ByVal ConnectionString As String, ByRef succeed As Boolean) As DataView

        Dim connection As SqlConnection
        Dim command As SqlCommand
        Dim adapter As New SqlDataAdapter
        Dim ds As New DataSet

        connection = New SqlConnection(ConnectionString)

        Try
            connection.Open()

            command = New SqlCommand(SqlString, connection)

            adapter.SelectCommand = command
            adapter.Fill(ds, "Create DataView")
            adapter.Dispose()
            command.Dispose()
            connection.Close()
            succeed = True
            Return ds.Tables(0).DefaultView
        Catch ex As Exception
            succeed = False
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return Nothing
        End Try

    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        StoreToolTipCtrl1.Control = PBox

        StoreToolTipCtrl1.Text = PBox.zSelectedProvider.LAName & " " & PBox.zSelectedProvider.UPIN

        StoreToolTipCtrl1.Title = PBox.zSelectedProvider.ProviderName

        StoreToolTipCtrl1.Show(3000, ToolTipIcon.None)

        MessageBox.Show(FilterCtrl1.zFilter)

    End Sub


    Private Sub PeriodBoxCtrl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PeriodBoxCtrl1.SelectedIndexChanged
        PBox.zPeriodID = PeriodBoxCtrl1.zSelectedPeriod_ID


    End Sub

    Private Sub TerritoryBoxCtrl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TerritoryBoxCtrl1.SelectedIndexChanged
        PBox.zTerritoryCodeFilter = TerritoryBoxCtrl1.zSelectedTerritory_Code


        LaBoxCtrl1.zTerritoryCodeFilter = TerritoryBoxCtrl1.zSelectedTerritory_Code


    End Sub

    Private Sub LaBoxCtrl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LaBoxCtrl1.SelectedIndexChanged
        PBox.zLACodeFilter = LaBoxCtrl1.zSelectedLA_Code


    End Sub

  
End Class
